home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-06-23 | 6.3 KB | 213 lines |
- /*
- * quicktime.app Library
- *
- * © 1996, Copyright, Apple Computer
- * All rights reserved
- *
- * $Workfile:: ControlPanel.java $
- * $Archive:: /Biscotti/QTJavaDemos/QTEffects/src/qteffect/ControlPanel.java $
- *
- * Authors: Bill Stewart
- */
- package qteffect;
-
- import java.awt.*;
- import java.awt.event.*;
-
- import quicktime.*;
- import quicktime.std.image.*;
- import quicktime.app.image.QTTransition;
- import quicktime.app.display.*;
- import PlayQTEffectApp;
- /**
- * A simple panel of AWT objects to demonstrate how AWT can be used to control a
- * QuickTime movie.
- */
- public class ControlPanel extends Panel implements Errors {
- //_________________________ CLASS METHODS
-
- public ControlPanel (QTTransition ef, QTCanvas c) throws QTException {
- this.transition = ef;
- final QTCanvas cv = c;
-
- GridBagLayout gb = new GridBagLayout();
- setLayout (gb);
- setFont (new Font("Helvetica", Font.BOLD, 10));
-
- GridBagConstraints cons = new GridBagConstraints();
- cons.fill = GridBagConstraints.HORIZONTAL;
- cons.gridheight = 1;
- cons.insets = new Insets (2, 2, 2, 2);
-
- cons.gridx = 0;
- cons.gridy = 0;
- cons.gridwidth = 3;
-
- add (runEffectButton, cons);
-
- cons.gridx = 3;
- add (chooseEffectButton, cons);
-
- cons.gridwidth = 2;
- cons.gridy = 1;
- cons.gridx = 0;
- add (timeLabel, cons);
-
- cons.gridx = 2;
- add (timeField, cons);
-
- cons.gridx = 4;
- add (timeButton, cons);
-
- cons.gridy = 2;
- cons.gridx = 0;
- add (frameLabel, cons);
-
- cons.gridx = 2;
- add (frameField, cons);
-
- cons.gridx = 4;
- add (frameButton, cons);
-
- cons.gridy = 3;
- cons.gridx = 0;
- add (fpsLabel, cons);
-
- cons.gridx = 2;
- add (fpsField, cons);
-
- timeField.addActionListener (new ActionListener () {
- public void actionPerformed (ActionEvent event) {
- String str = new String (event.getActionCommand());
- String output = "";
- for (int i = 0; i < str.length(); i++) {
- if (Character.isDigit (str.charAt (i)))
- output += str.charAt (i);
- else
- break;
- }
- try {
- transition.setTime (new Integer (output).intValue());
- timeField.setText (Integer.toString (transition.getTime()));
- frameField.setText (Integer.toString (transition.getFrames()));
- } catch (QTException e) {
- e.printStackTrace();
- }
- }
- });
- frameField.addActionListener (new ActionListener () {
- public void actionPerformed (ActionEvent event) {
- String str = new String (event.getActionCommand());
- String output = "";
- for (int i = 0; i < str.length(); i++) {
- if (Character.isDigit (str.charAt (i)))
- output += str.charAt (i);
- else
- break;
- }
- try {
- transition.setFrames (new Integer (output).intValue());
- timeField.setText (Integer.toString (transition.getTime()));
- frameField.setText (Integer.toString (transition.getFrames()));
- } catch (QTException e) {
- e.printStackTrace();
- }
- }
- });
- fpsField.addActionListener (new ActionListener () {
- public void actionPerformed (ActionEvent event) {
- String str = new String (event.getActionCommand());
- String output = "";
- for (int i = 0; i < str.length(); i++) {
- if (Character.isDigit (str.charAt (i)))
- output += str.charAt (i);
- else
- break;
- }
- try {
- transition.setFramesPerSecond (new Integer (output).intValue());
- frameField.setText (Integer.toString (transition.getFrames()));
- } catch (QTException e) {
- e.printStackTrace();
- }
- }
- });
- runEffectButton.addActionListener (new ActionListener () {
- public void actionPerformed (ActionEvent event) {
- try {
- transition.doTransition();
- if (transition.isProfiled()) {
- String profileString = "Transition Profile:"
- + "requestedDuration:" + transition.getTime()
- + ",actualDuration:" + transition.profileDuration()
- + ",requestedFrames:" + transition.getFrames()
- + ",framesRendered=" + transition.profileFramesRendered()
- + ",averageRenderTimePerFrame=" + (transition.profileDuration() / transition.profileFramesRendered());
- System.out.println (profileString);
- }
-
- } catch (QTException e) {
- if (e.errorCode() != userCanceledErr)
- e.printStackTrace();
- }
- }
- });
- chooseEffectButton.addActionListener (new ActionListener () {
- public void actionPerformed (ActionEvent event) {
- try {
- PlayQTEffectApp.showDialog (transition);
- } catch (QTException e) {
- if (e.errorCode() != userCanceledErr)
- e.printStackTrace();
- }
- }
-
- });
-
- frameButton.addItemListener (new ItemListener () {
- public void itemStateChanged (ItemEvent event) {
- transition.doTime (false);
- }
- });
- timeButton.addItemListener (new ItemListener () {
- public void itemStateChanged (ItemEvent event) {
- transition.doTime (true);
- }
- });
-
- timeField.setText (Integer.toString (transition.getTime()));
- frameField.setText (Integer.toString (transition.getFrames()));
- fpsField.setText (Integer.toString (transition.getFramesPerSecond()));
- }
-
- //_________________________ INSTANCE VARIABLES
- private Button runEffectButton = new Button("Run Effect");
- private Button chooseEffectButton = new Button("Choose Effect");
-
- private Label timeLabel = new Label ("Effect Length (msecs):", Label.RIGHT);
- private TextField timeField = new TextField (8);
-
- private Label frameLabel = new Label ("Total Frames:", Label.RIGHT);
- private TextField frameField = new TextField (8);
-
- private Label fpsLabel = new Label ("Frames Per Second:", Label.RIGHT);
- private TextField fpsField = new TextField (8);
-
- private CheckboxGroup cbg = new CheckboxGroup ();
- private Checkbox timeButton = new Checkbox ("Time", cbg, true);
- private Checkbox frameButton = new Checkbox ("Frames", cbg, false);
-
- private QTTransition transition;
-
- //_________________________ INSTANCE METHODS
- /**
- * @return a Dimension object which defines the minimum size
- */
- public Dimension getMinimumSize() { return new Dimension (0, 100); }
-
- /**
- * @return a Dimension object which defines the preferred size
- */
- public Dimension getPreferredSize() { return getMinimumSize(); }
- }
-